package com.bkq.viettravel;

import java.util.ArrayList;

import android.R.integer;
import android.app.Activity;
import android.app.LauncherActivity.ListItem;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class ResultSearch extends Activity {
	
	//back button
	private Button backBtn ;
	// menuBar
	
	private Button homeBtn, favouriteBtn, planBtn, infoBtn;
	
	
	
	private ListView listTravel;
	private ArrayList<DataRS> listItem;
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.result_search);
        
        //back btn
        backBtn = (Button)findViewById(R.id.resutl_search_btn_back);
        
        //MenuBar
        homeBtn = (Button)findViewById(R.id.resutl_search_home);
        favouriteBtn = (Button)findViewById(R.id.resutl_search_favourites);
        planBtn = (Button)findViewById(R.id.resutl_search_plant);
        infoBtn =(Button)findViewById(R.id.list_hotel_Btn_info);
        listTravel = (ListView)findViewById(R.id.resutl_search_lv_listtravel);
        listItem = new ArrayList<DataRS>();
        listItem.add(new DataRS("http://www.phusontravel.com/phusontravel-images/product/img2/Ba_Na.jpg", "Ba Na Hill"));
        
        CustomAdapterRS adapte = new CustomAdapterRS(this,listItem);
        listTravel.setAdapter(adapte);
        listTravel.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Intent i  = new Intent(ResultSearch.this, InformationTravelActivity.class);
				startActivity(i);	
			}
		});
        
        backBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				finish();
				
			}
		});
        
        homeBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {

				finish();
				
			}
		});
       favouriteBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent i = new Intent(ResultSearch.this, FavoritesActivity.class);
				startActivity(i);
				
			}
		});
        
        planBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				Intent i = new Intent(ResultSearch.this,Plan.class);
				startActivity(i);
			}
		});
        
        infoBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent i = new Intent(ResultSearch.this,InformationTravelActivity.class);
				startActivity(i);
				
			}
		});
    }


	
/*
 * Het class chinh
 * */	
}
class DataRS
{
	String urlimg ="";
	String textItem="";
	public DataRS(String urlimg, String textItem) {
		this.urlimg = urlimg;
		this.textItem = textItem;
	}
	
}
class CustomAdapterRS extends BaseAdapter {
	LayoutInflater mInflate ;
	ArrayList<DataRS> mlist ;
	
	public CustomAdapterRS(Context contex, ArrayList<DataRS> list) {
		mInflate = LayoutInflater.from(contex);
		mlist = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mlist.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mlist.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHold holder = new ViewHold();
		if(convertView == null)
		{
			convertView = mInflate.inflate(R.layout.adapte_list_travel,null);
			holder.img = (LoaderImageView) convertView.findViewById(R.id.adapte_list_travel_imag);
			holder.tv = (TextView)convertView.findViewById(R.id.adapte_list_travel_tv1);
			convertView.setTag(holder);
		}
		
		else
		{
			holder = (ViewHold)convertView.getTag();
		}
		
			holder.tv.setText(mlist.get(position).textItem);
			holder.img.setImageDrawable(mlist.get(position).urlimg, 100, 200);
		return convertView;
	}
	
	class ViewHold
	{
		public LoaderImageView img;
		public TextView tv;
		
	}
	
}
